/*
* @Author: dengjiayao
* @Date:   2017-06-28 11:14:28
* @Last Modified by:   dengjiayao
* @Last Modified time: 2017-07-05 13:40:08
*/

import { modal } from 'vue-strap'
import { addCastTalkUserAuth, showMsg } from '../../vuex/action'

export default {
  name: 'cast-talk-user-subscribe',
  components: {
    'vue-modal': modal
  },
  data() {
    return {
      showModal: false,
      form: {
        userId: null,
        type: -1,
        value: ''
      }
    }
  },
  vuex: {
    actions: {
      xShowMsg: showMsg,
      xVip: addCastTalkUserAuth
    }
  },
  methods: {
    valid() {
      let {type, value} = this.form
      if (type < 0) {
        return Promise.reject({
          msg: '请选择订阅类型'
        })
      }
      if ((value + '').length === 0) {
        return Promise.reject({
          msg: +type === 0 ? '请填写期刊ID' : '请填写订阅数'
        })
      }
      return Promise.resolve()
    },
    submit() {
      this.xVip(this.form)
        .then(() => {
          this.showModal = false
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.msg
          })
        })
    }
  }
}
